package springboot.Controller;

import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import springboot.common.BaseContext;
import springboot.common.Constants;
import springboot.common.R;
import springboot.common.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import springboot.entity.LjhsOrder;
import springboot.mapper.LjhsAddressMapper;
import springboot.mapper.LjhsOrderMapper;
import springboot.service.ILjhsAddressService;
import springboot.entity.LjhsAddress;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hys
 * @since 2022-06-02
 */
@RestController
@RequestMapping("/ljhsaddress")
public class LjhsAddressController {
    @Resource
    private ILjhsAddressService ljhsAddressService;

    @PostMapping

    public Result save(@RequestBody LjhsAddress ljhsAddress){

        return Result.success(ljhsAddressService.saveOrUpdate(ljhsAddress));
        }

        @DeleteMapping("/{id}")

        public Result delete(@PathVariable Integer id){


        return Result.success(ljhsAddressService.removeById(id));
        }

        @PostMapping("/batch/del")
        public Result deleteBatch(@RequestBody List<Integer> ids){

        return Result.success(ljhsAddressService.removeByIds(ids));
        }


        @GetMapping("/page")

        public Result findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize) {
        return Result.success(ljhsAddressService.page(new Page<>(pageNum, pageSize)));
        }
      @GetMapping("/{userId}")

     public Result findOne(@PathVariable Integer userId) {

        if (userId == null) {
            Result.error(Constants.CODE_400, "参数错误");
        } else {
            Result.success(ljhsAddressService.list(new QueryWrapper<LjhsAddress>().eq("user_id", userId)));
        }
        return  Result.success(ljhsAddressService.list(new QueryWrapper<LjhsAddress>().eq("user_id", userId)));
    }



}

